import request from '@/utils/request'

// 引入自己的 request.js
import ajax from './request'

// 获取人员信息列表数据
export const getUsers = (page = 1, pageSize = 5) => ajax({
  url: `/api/v1/users?page=${page}&pageSize=${pageSize}`,
  method: 'GET'
})

// 修改人员信息
export const udpateUser = userinfo => ajax({
  url: '/api/v1/users',
  method: 'PUT',
  data: userinfo
})

// 添加人员信息
// export const addUser = userinfo => ajax({
//   url: '/api/v1/users',
//   method: 'POST',
//   data: userinfo
// })
export const addUser = userinfo => ajax({
  url: '/api/v1/users',
  method: 'POST',
  data: userinfo,
  headers: {
    'Content-Type': 'multipart/form-data'
  }
})

// 删除人员信息
export const deleteUser = _id => ajax({
  url: '/api/v1/users/' + _id,
  method: 'DELETE'
})

export function login(data) {
  return request({
    url: '/vue-element-admin/user/login',
    method: 'post',
    data
  })
}

export function getInfo(token) {
  return request({
    url: '/vue-element-admin/user/info',
    method: 'get',
    params: { token }
  })
}

export function logout() {
  return request({
    url: '/vue-element-admin/user/logout',
    method: 'post'
  })
}

